/*
Arm Tracker and Glove Demo by Noah Zerkin (noazark AT gmail.com) 2009
Released under GNU GPLv3.0 http://www.opensource.org/licenses/gpl-3.0.html
*/

void zeroGyro(){
  if(buttonC){
    if(buttonZ){
      gxZero = gxRaw;
      gyZero = gyRaw;
    }
  }
  if(!buttonC){
    if(buttonZ){
      mainMenu.activate(true);
    }
    else{
      mainMenu.activate(false);
    }
  }
  if(keyPressed){
    if (key == CODED) {
      if (keyCode == UP) {
        joyY += -30;
      } 
      else if (keyCode == DOWN) {
        joyY += 30;
      }  
      else if (keyCode == LEFT) {
        joyX += 30;
      }  
      else if (keyCode == RIGHT) {
        joyX += -30;
      } 
    }
    if(key == '['){
      zoom -= 10;
    }
    if(key == ']'){
      zoom += 10;
    }
  }
  if(keyPressed && !pressed && key != CODED) {
    if(key == '/'){
      joyX = 0; 
      joyY = 0;
    }
    if(key == 'g'){
      if(gyro){
        gyro = false;
      } 
      else{
        gyro = true;
      }
    }
    if(key == '1'){
      pistol.fire();
    }
    if(key == 'p'){
      if(pov){
        pov = false;
      } 
      else{
        pov = true;
      }
    }
    if(key == 'r'){
      yRot[0] = 0.0; 
      yRot[1] = 0.0;
    }
    if(key == ','){
      findMin(0);
    }
    if(key == '.'){
      findMax(0);
    }
    if(key == ';'){
      findMin(1);
    }
    if(key == '\''){
      findMax(1);
    }
    if(key == 't'){
      if(thumbStickOn){
        thumbStickOn = false;
      } 
      else{
        thumbStickOn = true;
      }
    }
    if(key == 'b'){
      if(worldBox){
        worldBox = false;
      } 
      else{
        worldBox = true;
      }
    }
    if(key == 'a'){
      if(body){
        body = false;
      } 
      else{
        body = true;
      }
    }
    if(key == 'c'){
      //     vr920.ZeroSet();
    }
    if(key == 'z'){
      gxZero[0] = gxRaw[0]; 
      gyZero[0] = gyRaw[0]; 
      gxZero[1] = gxRaw[1]; 
      gyZero[1] = gyRaw[1];
    }
    if( key == 'x' ){
         //  vr920.ZeroClear();
    }
    if(key == 'f'){
      flex90[0] = int(flexVal[0]); 
      println(flex90[0]);
    }
    if(key == 'd'){
      flex180[0] = int(flexVal[0]); 
      println(flex180[0]);
    }
    if(key == 'w'){
      flex90[1] = int(flexVal[1]);
    }
    if(key == 'q'){
      flex180[1] = int(flexVal[1]);
    }
    if(key == 'v' ){
      if(vid){
        vid = false;
      } 
      else{
        vid = true;
      }
    }
    //    if(key == 'm' ){if(myron){myron = false;} else{myron = true;}}
    if(key == 'o' ){
      if(reticle){
        reticle = false;
      } 
      else{
        reticle = true;
      }
    }
    if(key == 'y'){
           // vr920.BeginCalibrate();
    }
    if( key == 'u' ) {
          //  vr920.EndCalibrate( true );
    }
    if( key == 'i' ) {
      port.write('a');
    }
    if( key == 'k' ) {
      port.write('c');
    }
    if( key == 'l' ) {
      port.write('v');
    }
    if( key == 'j' ) {
      port.write('b');
    }
    if(key == 'Q'){
      exit();
    }
    if(key == '0'){
      for (int i = boxes.size()-1; i >= 0; i--) { 
        // An ArrayList doesn't know what it is storing so we have 
        // to cast the object coming out
        PersistantBox drawnBox = (PersistantBox) boxes.get(i);
        boxes.remove(i);
      }  
    }

    if(key == '1'){
      createTargets();
    }

    if(key == '2'){
      clearTargets();
    }

    pressed = true;
  }
  if(!keyPressed && pressed){
    pressed = false;
  }

}
